<template>
  <el-dialog
    :title="'选择商家(爱车检修)'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-table
      ref="singleTable"
      :data="dataList"
      highlight-current-row
      @current-change="handleCurrentChange"
      style="width: 100%"
    >
      <el-table-column type="index"> </el-table-column>
      <el-table-column property="name" label="商家"> </el-table-column>
      <el-table-column property="address" label="地址"> </el-table-column>
      <el-table-column property="contactInfo" label="联系方式">
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()"
        >给该商家发送预约申请</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import _ from "lodash";
import moment from "moment";
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: ""
      },
      currentRow: null,
      dataList: []
    };
  },
  methods: {
    getDataList() {
      this.$http({
        url: this.$http.adornUrl(`/shop/list`),
        method: "get"
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
        }
      });
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    init(id) {
      this.dataForm.carId = id || 0;
      this.visible = true;
      this.getDataList();
    },

    guid() {
      return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
        c
      ) {
        var r = (Math.random() * 16) | 0,
          v = c == "x" ? r : (r & 0x3) | 0x8;
        return v.toString(16);
      });
    },
    // 表单提交
    dataFormSubmit() {
      if (!this.currentRow) {
        this.$message.error("请选择商家");
        return;
      }
      const params = {};
      params.userId = this.getUserId();
      params.beginTime = moment().format("YYYY-MM-DD HH:mm:ss");
      params.carId = this.dataForm.carId;
      params.shopId = this.currentRow.shopId;
      params.applyId =1;
       params.endTime="2022-04-20 23:23:23";
      params.repairPrice = 0;
      this.$http({
        url: this.$http.adornUrl(`/repair/save`),
        method: "post",
        data: this.$http.adornData(params)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    }
  }
};
</script>
